{{include file ="admin/header.tpl"}} {{include file
="admin/navibar.tpl"}} {{include file ="admin/sidebar.tpl"}}


<link rel="stylesheet" type="text/css"
	href="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/themes/icon.css">

<style type="text/css">
#addwin {
	margin: -500px 0 0 -280px;
	/* PLAY THE WITH THE VALUES TO SEE GET THE DESIRED EFFECT */
}
</style>
<script type="text/javascript"
	src="{{$smarty.const.WEBSITE_URL}}/public/assets/lib/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="{{$smarty.const.WEBSITE_URL}}public/assets/lib/ajaxupload.js"></script>
<script type="text/javascript">


//文件上传组件处理
jQuery(function () {
	 	var button = jQuery('#selectfile');//绑定事件
	var load = new AjaxUpload(button, {//绑定AjaxUpload
    action: "{{$smarty.const.WEBSITE_URL}}admin/fileupload/fileup",//文件要上传到的处理页面,语言可以PHP,ASP,JSP等
    type:"POST",//提交方式
    data:{//还可以提交的值
        module:"ajaxupload",
        type:jQuery("#__mstype__").attr("value"),
    },
    autoSubmit:true,//选择文件后,是否自动提交.这里可以变成true,自己去看看效果吧.
    name:'msUploadFile',//提交的名字
    onChange:function(file,ext){//当选择文件后执行的方法,ext存在文件后续,可以在这里判断文件格式
		$("#ad_file_location").attr("value",file);
    },
    onSubmit: function (file, ext) {//提交文件时执行的方法
    	if(ext && /^(jpg|jpeg|png|gif)$/.test(ext)){
			//ext是后缀名
    		button.value = "正在上传…";
    		button.disabled = "disabled";
		}else{	
			alert("不支持的文件格式！只能上传jpg|jpeg|png|gif") ;
			return false;
		}
    },
    onComplete: function (file, response) {//文件提交完成后可执行的方法
        button.text('浏览');
        this.enable();
		var data=eval("("+response+")");
		if(data.type==0){
			alert(data.message);
		}else{
			$('#ad_file_location').val(data.filename);
		}
    }
});
//	var submit=jQuery('#subm').click(function(){//触发提交的事件.与autoSubmit的设置有关,是否采用
//		load.submit();
//});
});
	loadSites();
 
	function addWindow(){
		 loadSites();
		modelshow();
		$("#form").form('clear');
	}
	function editWindow(){
		var select = getSelect();
		if(select == null || select.length == 0 ){
			$.messager.alert('错误','请选择要修改的记录!');
			return;
		}
		 loadSites();
		modelshow();
		$("#form").form('clear');
		$("#form").form('load',select[0]);

	
	}

	 

	
	function deleteItem(){

		$.messager.confirm('Confirm','Delete the currently selected record!',function(r){
		    if (r){
		    	var select = getSelect();
				if(select == null || select.length == 0 ){
					$.messager.alert('ERROR','Please select the record!');
					return;
				}
				$.ajax({  
		            type: "POST",  
		            dataType: "json",  
		            url: '{{$smarty.const.WEBSITE_URL}}admin/advertising/delete',
		            data: { id: select[0].ad_id },  
		            success: function (data) {  
		              //  $.messager.alert("消息", "删除成功!", "info");  
		             	$('#grid').datagrid('reload'); 
		            },  
		            error: function () {  
		            }  
		        });  
		    }
		});
		
	}

	
	function submitStatusChange (){
		  if(!$('#form').form('validate')){
		        return;
		     }
			    $.post(
						'{{$smarty.const.WEBSITE_URL}}admin/advertising/add',
						$('#form').serialize(),
						function(data){ 
							modelhide();
					    	$('#grid').datagrid('reload'); 
						},
						"json"
			    );
	}
	  
	function win_close(){
		$('#win_add').window('close'); 
	}


	function getSelect(){
		var select  = $("#grid").datagrid('getSelections');
		if(select == null || select.length == 0 ){
			return null;
		}
		return select;
	}

	function formateType(value,row,index){
		if(value == null || value ==""){
			return ""; 
		}
		if(value == 0){
			return "文件上传";
		}
		if(value == 1){
			return "在线地址";
		}
		 return "";
	}
	 function modelshow(){ 
		 $('#addwin').modal('show');
	 }
	 function modelhide(){
		 $('#addwin').modal('hide');
	 }

	 var satelite;
		function loadSites(){
			 if(satelite != null){
				 document.getElementById("ad_site_id").innerHTML=createOptions(satelite);  
				 return;
			 }
			 $.ajax({
		            type: "POST",
		            data: { table: "TCA_SATELLITE_LIST" },
		            url: '{{$smarty.const.WEBSITE_URL}}admin/adsite/getStaticSites',
		            success:function(data){
		            	 var data = $.parseJSON(data);
		            	 satelite = data;
			    		 document.getElementById("ad_site_id").innerHTML=createOptions(data);  
				    },
		            error: function () {
		            }
		        });

			
		 }
		  function createOptions(data){
			 var name = "";
			 for(var i=0;data!=null&&i<data.length;i++){  
			   var cudata=data[i];  
			   name=name+"<option value='"+cudata.site_id+"'>"+cudata.site_name+"</option>"  
			 }  
			 return name;
		 }
		 
		  function changeImageType(value){
			  if(value =="0"){
				  $('#selectfile').css("display","block"); 
				  $('#ad_file_location').attr("readOnly",true); 
			  }else{
				  $('#selectfile').css("display","none"); 
				  $('#ad_file_location').attr("readOnly",false); 
			  }
			 
		  }
</script>

<div class="content">
	<div class="header">
		<div class="stats">
			<p class="stat">
				<!--span class="number"></span-->
			</p>
		</div>

		<h1 class="page-title">广告管理</h1>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">

			<!--- START 以上内容不需更改，保证该TPL页内的标签匹配即可 --->
			<table id="grid"
				data-options="url:'{{$smarty.const.WEBSITE_URL}}admin/advertising/getpage',fitColumns:true,singleSelect:true"
				class="easyui-datagrid" style="width: auto; height: 370px"
				toolbar="#toolbar" iconCls="icon-save" pagination="true"
				rownumbers="true">
				<thead>
					<tr>
						<th data-options="field:'ad_site_id',width:100,hidden:true"></th>
						<th data-options="field:'ad_id',width:100,checkbox:true"></th>
						<th data-options="field:'ad_title',width:100">广告头信息</th>
						<th data-options="field:'ad_description',width:100">描述</th>
						<th data-options="field:'ad_href',width:100">广告链接</th>
						<th
							data-options="field:'ad_file_type',width:100,formatter:formateType">图片类型</th>
						<th data-options="field:'ad_file_location',width:100">图片地址</th>
						<th data-options="field:'ad_count',width:100">点击次数</th>
						<th data-options="field:'ad_index',width:100">显示顺序</th>
						<th data-options="field:'ad_c_date',width:100">创建时间</th>
						<th data-options="field:'ad_u_date',width:100">最后修改时间</th>
						<th data-options="field:'site_name',width:100">广告位置</th>
						<th data-options="field:'ad_description',width:100">描述</th>
					</tr>
				</thead>
			</table>

			<div id="toolbar">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add"
					plain="true" onclick="addWindow()">添加</a> <a href="javascript:void(0)"
					class="easyui-linkbutton" iconCls="icon-edit" plain="true"
					onclick="editWindow()">修改</a> <a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-remove" plain="true" onclick="deleteItem()">删除</a>
			</div>


			<div id="addwin" class="modal hide fade">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h5>广告内容管理</h5>
				</div>
				<div class="modal-body">
					<form id="form" method="post" class="form-horizontal">
						<div class="control-group" hidden="true">
							<input type="text" id="ad_id" name="ad_id" hidden="true">
						</div>


						<div class="control-group">
							<label class="control-label" for="Text input">广告头信息:</label>
							<div class="controls">
								<input id="ad_title" placeholder="广告头信息." name="ad_title"></input>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">广告位置:</label>
							<div class="controls">
								<select id="ad_site_id" name="ad_site_id">
								</select>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label" for="Text input">广告链接:</label>
							<div class="controls">
								<input id="ad_href" placeholder="广告链接..." name="ad_href"></input>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label" for="Text input">图片类型:</label>
							<div class="controls">
								<select id="ad_file_type" name="ad_file_type"
									onchange="changeImageType(value);">
									<option selected="selected" value="0">手工上传</option>
									<option value="1">在线地址</option>
								</select>
							</div>
						</div>


						<div class="control-group" id="imguploadchose">
							<label class="control-label" for="Text input">图片:</label>
							<div class="controls">
								<input type="text" id="ad_file_location" name="ad_file_location"
									placeholder="图片地址位置" class="input-style4 textinput-w3" /> <input
									type="button" class="btn btn-small" id="selectfile"
									style="display: none" value="图片选择" />
							</div>
						</div>


						<div class="control-group">
							<label class="control-label" for="Text input">显示位置:</label>
							<div class="controls">
								<select id="ad_index" name="ad_index">
									<option selected="selected">1</option>
									<option>2</option>
									<option>3</option>
									<option>4</option>
									<option>5</option>
									<option>6</option>
									<option>7</option>
									<option>8</option>
									<option>9</option>
									<option>10</option>
									<option>11</option>
									<option>12</option>
									<option>13</option>
									<option>14</option>
									<option>15</option>
									<option>16</option>
									<option>17</option>
									<option>18</option>
									<option>19</option>
									<option>20</option>
								</select>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">描述:</label>
							<div class="controls">
								<textarea rows="2" id="ad_description" placeholder="描述..."
									name="ad_description"></textarea>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer" id="div_view">
					<button class="btn btn-success" onclick="submitStatusChange()"
						type="button" style="width: 100px; align: right;" class="btn">提交</button>
					<button class="btn" onclick="modelhide()" type="button"
						style="width: 100px; align: right;">取消</button>

				</div>
			</div>



			<!--- END 以下内容不需更改，请保证该TPL页内的标签匹配即可 --->
			{{include file="admin/footer.tpl" }}